package com.design.pattern.flyweight.ticket;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @version 1.0
 * @author: CRM_SYSTEM
 * @date: 2022/10/18 22:22
 * @Description:
 */
public class TicketFactory {

    private static Map<String,ITicket> POOL=new ConcurrentHashMap<>();


    public static ITicket queryTicket(String from,String to){
        String key=from+"->"+to;
        if (POOL.containsKey(key)){
            System.out.println("使用缓存"+key);
            return POOL.get(key);
        }
        System.out.println("首次查询，创建对象。"+key);
        TrainTicket ticket = new TrainTicket(from, to);
        POOL.put(key,ticket);
        return ticket;
    }
}
